package com.yb.smart.plugin.controller;

import com.gitee.starblues.bootstrap.annotation.AutowiredType;
import com.yb.smart.api.ReceiveDataHandle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 如何是web端调用插件中的方法，
 * 测试环境：请求路径前缀为 http://120.78.186.240:1050/plugins/插件ID/device/receive
 * 生产环境：请求路径前缀为 http://120.79.199.37:1050/plugins/插件ID/device/receive
 */
@RestController
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    @AutowiredType(AutowiredType.Type.PLUGIN_MAIN)
    ReceiveDataHandle receiveDataHandle;

    @RequestMapping("/register")
    public String register(String productKey, String productSecret, String mac) {
        return receiveDataHandle.register(productKey, productSecret, mac);
    }

    /**
     * 接收数据
     * @param productId
     * @param mac
     * @param data 上传事件：{"function_type":"event","identifier":"unlock","mac":"2124242342", "serialno":"dfa2wq122q"}
     *             上传属性：{"function_type":"property","identifier":"unlock","mac":"2124242342", "serialno":"dfa2wq122q"}
     * @return
     */
    @RequestMapping("/receive")
    public String receive(String productId, String mac, String data) {
        return receiveDataHandle.receive(productId, mac, data);
    }
    @RequestMapping("/connect")
    public String receive(String productId, String mac) {
        return receiveDataHandle.connect(productId, mac);
    }
    @RequestMapping("/disconnect")
    public String disconnect(String productId, String mac) {
        return receiveDataHandle.disconnect(productId, mac);
    }

}
